﻿using Microsoft.Extensions.DependencyInjection;
using System.Data.SqlClient;
namespace Gaea.SqlServer
{
    public static class GaeaSqlServerExtension
    {
        public static IServiceCollection AddGaeaSqlServer(this IServiceCollection serviceCollection, string connectionString, string connectionName = "SqlServer", MultipleConnectionType multipleConnectionType = MultipleConnectionType.Default)
        {
            serviceCollection.AddGaeaCore<SqlConnection>(new GaeaSqlServerAdapter());
            serviceCollection.AddGaeaOption(() =>
            {
                return new GaeaOption()
                {
                    ConnectionName = connectionName,
                    ConnectionString = connectionString,
                    GaeaNameSymbo = new string[] { "[", "]" },
                    BaseTypeGaeaPower = typeof(GaeaSqlServerPower),
                    ConnectionType = multipleConnectionType,
                    TypeOfDbConnection = typeof(SqlConnection)
                };
            }).AddGaeaOption(() =>
            {
                return new GaeaOption()
                {
                    ConnectionName = connectionName,
                    ConnectionString = connectionString,
                    GaeaNameSymbo = new string[] { "[", "]" },
                    BaseTypeGaeaPower = typeof(GaeaSqlServerPower<>),
                    ConnectionType = multipleConnectionType,
                    TypeOfDbConnection = typeof(SqlConnection)
                };
            });
            return serviceCollection;
        }
    }
}
